package com.wpml.cloud.classroom.handler;

import cn.hutool.json.JSONUtil;
import com.wpml.cloud.classroom.msg.Message;
import com.wpml.cloud.classroom.msg.MessageType;
import io.netty.channel.Channel;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Component;

/**
 * @Description
 * @Date 2021-05-13
 * @Author wangpei
 **/
@Component
public class BeginHandler implements MsgHandler {

    private static final Logger log = LogManager.getLogger(BeginHandler.class);

    @Override
    public void handleMsg(Message<String> msg, Channel chanel) {
        System.out.println("======BeginHandler=====");
        log.info("======BeginHandler===== {}", msg);

        chanel.writeAndFlush(new TextWebSocketFrame(JSONUtil.toJsonStr(msg)));
    }

    @Override
    public String getMsgId() {
        return MessageType.LOGIN;
    }
}
